package com.hsj.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import dto.Reponse;
import dto.TransData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import pojo.User;

/**
 * @author:Teacher黄
 * @date:Created at 2020/01/01
 */
@Service
public class RibbonService {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallBack")
    public TransData postUser(){
        User user = new User();
        user.setUserName("哈哈");
        return restTemplate.postForObject("http://SERVICE01/service01/user",user,TransData.class);
    }


    /**
     * 回调
     * @return
     */
    private TransData fallBack(){
        return Reponse.error(1001,"网络异常!");
    }


}
